<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!--公用头部-->
    <th:block th:replace="common/head::commonHead('定时任务编辑-小邑')"/>
    <style>
        #formAdvForm .layui-row {
            margin-top: 20px;
        }

        #formAdvForm .layui-form-item {
            margin-bottom: 0;
        }

        #formAdvForm .layui-form-item .layui-inline {
            margin-bottom: 25px;
            margin-right: 0;
        }
    </style>
</head>
<!--公用js-->
<th:block th:replace="common/head::commonJs"/>
<script>
    var type = null;
    var url = null;
    var jobId = null;
    $(function () {
        jobId = utils.request.getQueryString("jobId");
        type = utils.request.getQueryString("type");
        if (type == 1) {
            url = basePath + '/scheduleJob/addScheduleJob';
        } else {
            url = basePath + '/scheduleJob/updateScheduleJob';
        }
    })
</script>
<body marginwidth="0" marginheight="0">
<form class="layui-form" action="" id="formAdvForm" lay-filter="formAdvForm">
    <div class="layui-fluid  layui-fluid-btn">
        <div class="layui-col-md12">
            <div class="layui-card" style="margin: 10px;">
                <div class="layui-card-body">
                    <input name="jobId" type="text" style="display: none">
                    <div class="layui-form-item layui-row">
                        <div class="layui-inline layui-col-md6">
                            <label class="layui-form-label layui-form-required">任务名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="jobName" id="jobName" lay-verify="required" placeholder="任务名称"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md6">
                            <label class="layui-form-label layui-form-required">运行类</label>
                            <div class="layui-input-block">
                                <input type="text" name="beanName" id="beanName" lay-verify="required" placeholder="运行类"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md6">
                            <label class="layui-form-label layui-form-required">参数</label>
                            <div class="layui-input-block">
                                <input type="text" name="params" id="params" lay-verify="required" placeholder="参数"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md6">
                            <label class="layui-form-label layui-form-required">表达式</label>
                            <div class="layui-input-block">
                                <input type="text" name="cronExpression" id="cronExpression" lay-verify="required"
                                       placeholder="执行表达式" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md6">
                            <label class="layui-form-label layui-form-required">状态</label>
                            <div class="layui-input-block">
                                <input name="status" title="运行" type="radio" value="0">
                                <input checked name="status" title="挂起" type="radio" value="1">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md6">
                            <label class="layui-form-label layui-form-required">描述</label>
                            <div class="layui-input-block">
                                <textarea class="layui-textarea" name="remark" placeholder="任务描述"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="form-group-bottom">
                        <button class="xy-btn xy-btn-primary subCheckBtn" lay-submit lay-filter="formBtn">提交</button>
                        <button type="reset" class="xy-btn ">重置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        //监听提交
        form.on('submit(formBtn)', function (data) {
            var formDate = data.field;
            if (type == 2) {
                if (isEmpty(formDate.jobId)) {
                    formDate.jobId = jobId;
                }
            }
            var loadIndex = null;
            checkSubBtn(1);
            sendAjaxPostToCallback(
                url,
                formDate,
                function (result) {
                    if (result.success) {
                        // 提示信息
                        top.layui.notice.msg(result.msg, {icon: 1, position: "topCenter"});
                        // 获取当前iframe层的索引
                        var index = parent.layer.getFrameIndex(window.name);
                        // 关闭弹窗
                        parent.layer.close(index);
                        // 重载表格
                        parent.layui.table.reload('jobTable', {});
                    } else {
                        checkSubBtn(2);
                        top.layui.notice.msg(result.msg, {icon: 2, position: "topCenter"});
                    }
                },
                function (data) {
                    checkSubBtn(2);
                    if (utils.string.isEmpty(data) && utils.string.isEmpty(data.msg)) {
                        top.layui.notice.msg(data.msg, {icon: 2, position: "topCenter"});
                    } else {
                        top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2, position: "topCenter"});
                    }
                },
                function () {
                    loadIndex = layer.load(1);
                },
                function () {
                    layer.close(loadIndex);
                },
            )
            return false;
        });
        /*修改回填表单*/
        if (type == 2) {
            //获取详情信息，填充表单
            var loadIndex = null;
            sendAjaxPostToCallbackAsync(
                basePath + '/scheduleJob/list',
                {jobId: jobId},
                false,
                function (result) {
                    if (result.success == true) {
                        layui.form.val('formAdvForm', result.data[0]);
                    } else {
                        top.layui.notice.msg(result.msg, {icon: 2, position: "topCenter"});
                    }
                },
                function (e) {
                    top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2, position: "topCenter"});
                },
                function () {
                    loadIndex = layer.load(1);
                },
                function () {
                    layer.close(loadIndex);
                },
            )
        }
    })
</script>
</body>
</html>